package day12;

import cn.hutool.core.io.IoUtil;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Random;

public class homework02 {
    public static void main(String[] args) throws Exception {
        BufferedReader reader1=IoUtil.getReader(new FileReader("womannames.txt"));
        BufferedReader reader2=IoUtil.getReader(new FileReader("mannames.txt"));
        ArrayList<String> names=insertnames(reader1,reader2);
        reader2.close();
        reader1.close();
        named(names);
    }

    public static void named(ArrayList<String> names) {
        Random rm=new Random();
        int numbering=rm.nextInt(names.size());
        System.out.println(names.get(numbering));
    }

    public static ArrayList<String> insertnames(BufferedReader reader1, BufferedReader reader2) throws Exception {
        ArrayList<String> name = new ArrayList<>();
        String woname;
        while ((woname=reader1.readLine())!=null){
            name.add(woname);
        }
        String manname;
        while ((manname=reader2.readLine())!=null){
            name.add(manname);
        }
        return name;
    }
}
